<?php

//
//  Copyright (C) 2004-2006  Autodesk, Inc.
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of version 2.1 of the GNU Lesser
//  General Public License as published by the Free Software Foundation.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//
?>
<?php
    require_once 'JSON.php';
	require_once 'queryGruposMoviles.php';
	require_once 'queryMoviles.php';
    require_once 'queryPosiMoviles.php';
    require_once 'queryHistorico.php';
	require_once 'queryHistorico2.php';
    require_once 'queryPosiSelect.php';
    require_once 'queryUltimaSenial.php';
	require_once 'queryMisPuntos.php';
	require_once 'queryMisGrupos.php';
	require_once 'queryMisZonas.php';
	require_once 'queryMisComandos.php';
	require_once 'queryReglas.php';
	require_once 'queryEventosMoni.php';
	require_once 'queryEventosById.php';
	require_once 'queryKeepAlive.php';
	require_once 'queryEventos.php';
	require_once 'queryResoluciones.php';
	require_once 'queryEventoHistorico.php';
	require_once 'queryMantenimiento.php';
	require_once 'querySendMailStatus.php';
	require_once 'queryContacto.php';
	require_once 'queryInfoFijo.php';
	require_once 'queryViajes.php';

	require_once 'queryLogin.php';
	require_once 'queryConsultaPublicidad.php';
	require_once 'queryLogout.php';
	require_once 'queryEnviarSolicitud.php';

	require_once 'querySelectFlotas.php';
	require_once 'querySelectMoviles.php';
	require_once 'querySelectFijos.php';
	require_once 'queryRCs.php';
	require_once 'queryFijos.php';
	require_once 'queryAproxPoint.php';
	require_once 'queryInfoCuenta.php';
	require_once 'queryVerificaRegla.php';
	
	require_once 'queryEventosMoviles.php';
	require_once 'queryMisRutas.php';
	require_once 'queryMonitorearEventoCliente.php';

	require_once("config.php");
	require_once(ROOT_DIR_CLASES.'/PHPLogger.php');

	$LOGGER = new PHPLogger(LOGGER_PATH, LOGGER_LEVEL);

	$args = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST : $_GET;
    $json = new Services_JSON();
    if (array_key_exists('COMMAND', $args))
	{
		$cmd = $args['COMMAND'];
    	switch ($cmd) {
			case "MISGRUPOSVEHICULOS":
				$query = new QueryGruposMoviles($args);
				break;
			case "MOVILES":
				$query = new QueryMoviles($args);
				break;
			case "REFRESH":
				$query = new QueryPosiMoviles($args);
				break;
			case "HISTORICO":
				$query = new QueryHistorico($args);
				break;
			case "HISTORICO2":
				$query = new QueryHistorico2($args);
				break;
			case "VIEWPOINT":
				$query = new QueryPosiSelect($args);
				break;
			case "ULTIMASENIAL":
				$query = new QueryUltimaSenial($args);
				break;
			case "KEEPALIVE":
				$query = new QueryKeepAlive($args);
				break;
			case "MISPUNTOS":
				$query = new QueryMisPuntos($args);
				break;
			case "MISGRUPOS":
				$query = new QueryMisGrupos($args);
				break;
			case "MISZONAS":
				$query = new QueryMisZonas($args);
				break;
			case "MISCOMANDOS":
				$query = new QueryMisComandos($args);
				break;
			case "REGLAS":
				$query = new QueryReglas($args);
				break;
			case "MONITOR":
				$query = new QueryEventosMoni($args);
				break;
			case "EVENTOSBYID":
				$query = new QueryEventosById($args);
				break;
			case "MISEVENTOS":
				$query = new QueryEventos($args);
				break;
			case "MISEVENTOSMOVILES":
				$query = new QueryEventosMoviles($args);
				break;
			case "MISRESOLUCIONES":
				$query = new QueryResoluciones($args);
				break;
			case "SEARCHEVENTOHISTORICO":
				$query = new QueryEventoHistorico($args);
				break;
			case "MANTENIMIENTO":
				$query = new QueryMantenimiento($args);
				break;
			case "SENDMAILSTATUS":
				$query = new QuerySendMailStatus($args);
				break;
			case "CONTACTO":
				$query = new QueryContacto($args);
				break;
			case "INFOFIJO":
				$query = new QueryInfoFijo($args);
				break;
			case "LOGIN":
				$query = new QueryLogin( $args );
				break;
			case "CONSULTAPUBLICIDAD":
				$query = new QueryConsultaPublicidad( $args );
				break;
			case "LOGOUT":
				$query = new QueryLogout( $args );
				break;
			case "ENVIARSOLICITUD":
				$query = new QueryEnviarSolicitud( $args );
				break;
			case "CHANGESELECTFLOTAS":
				$query = new QuerySelectFlotas( $args );
				break;
			case "CHANGESELECTMOVILES":
				$query = new QuerySelectMoviles( $args );
				break;
			case "CHANGESELECTFIJOS":
				$query = new QuerySelectFijos( $args );
				break;
			case "CUENTASFIJOS":
				$query = new QueryFijos( $args );
				break;
			case "RC":
				$query = new QueryRCs( $args );
				break;
			case "VIAJES":
				$query = new QueryViajes( $args );
				break;
			case "APROXPOINT":
				$query = new QueryAproxPoint($args);
				break;
			case "INFOCUENTA":
				$query = new QueryInfoCuenta($args);
				break;
			case "VERIFICAREGLA":
				$query = new QueryVerificaRegla($args);
				break;
			case "CARGARMISRUTAS":
				$query = new QueryMisRutas($args);
				break;
			case "MONITOREAREVENTOCLIENTE":
				$query = new QueryMonitorearEventoCliente($args);
				break;
    	}
	}

    $response = $json->encode($query->Execute());
    header('Content-Type: text/plain');
    echo $response;
	
?>